/*
 * @Author: zxh
 * @Email: 1271027008@qq.com
 * @Date: 2020-03-18 11:29:40
 * @Descripttion: 
 */
import { Component, OnInit } from '@angular/core';
import { NzModalService } from 'ng-zorro-antd/modal';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-my-news',
  templateUrl: './my-news.component.html',
  styleUrls: ['./my-news.component.scss']
})
export class MyNewsComponent implements OnInit {

  constructor(
    private NzModalService: NzModalService,
    private fb: FormBuilder
  ) { }

  ngOnInit() {
    this.validateForm = this.fb.group({
      sender: ['', [Validators.required]],
      title: ['', [Validators.required]],
      content: ['', [Validators.required]]
    })
    this.modalDomBoxA = document.querySelector("#modal_box_1");
    this.modalDomBoxB = document.querySelector("#modal_box_2");
  }

  modalDomBoxA: any
  modalDomBoxB: any

  isAllDisplayDataChecked = false;
  isIndeterminate = false;
  listOfDisplayData = [];
  listOfAllData = [
    {
      id: 0,
      code: 123,
      theme: '123',
      time: '2020-03-18',
      sender: 'admin',
      mark: 'aaa'
    }
  ];
  mapOfCheckedId: { [key: string]: boolean } = {};
  numberOfChecked = 0;

  currentPageDataChange($event): void {
    this.listOfDisplayData = $event;
    this.refreshStatus();
  }
  refreshStatus(): void {
    this.isAllDisplayDataChecked = this.listOfDisplayData.every(item => this.mapOfCheckedId[item.id]);
    if (this.listOfAllData.length == 0) {
      this.isAllDisplayDataChecked = false
    }
    this.isIndeterminate =
      this.listOfDisplayData.some(item => this.mapOfCheckedId[item.id]) && !this.isAllDisplayDataChecked;
    this.numberOfChecked = this.listOfAllData.filter(item => this.mapOfCheckedId[item.id]).length;
  }
  checkAll(value: boolean): void {
    this.listOfDisplayData.forEach(item => (this.mapOfCheckedId[item.id] = value));
    this.refreshStatus();
  }

  // modal 1
  isVisibleLook: boolean = false
  sender: string = ''
  receiver: string = ''
  titleLook: string = ''
  contentLook: string = ''
  showLook() {
    this.isVisibleLook = true
  }
  handleCancelLook() {
    this.isVisibleLook = false
  }
  handleOkLook() {
    this.isVisibleLook = false
  }
  delNews() {
    this.NzModalService.confirm({
      nzTitle: '确定要删除吗？',
      nzOnOk: () => {

      }
    })
  }
  // modal 2
  isVisibleSend: boolean = false
  validateForm: FormGroup
  selectSender = []
  userList = []
  showSend() {
    this.isVisibleSend = true
  }
  handleCancelSend() {
    this.isVisibleSend = false
  }
  submitForm() {
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty();
      this.validateForm.controls[i].updateValueAndValidity();
    }
    if(this.validateForm.status=='VAILD'){
      let _value = this.validateForm.value
      this.isVisibleSend = false
    }
  }
  sendChange($event) {
    console.log($event)
  }

}
